﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using UnityEditor;

internal class FlashPostProcessSettings
{
    [CompilerGenerated]
    private static Func<string, KeyValuePair<string, object>, string> <>f__am$cache5;
    public UnityEditor.FlashBuildSubtarget FlashBuildSubtarget;
    public int Height;
    public bool IsDevelopment;
    public bool StripPhysics;
    internal const string UnityFlashConstantNamespace = "UNITY_FLASH";
    public int Width;

    private static void AddConfigDefineForFlashPlayerFeatureLevel(bool enabled, string level, IDictionary<string, object> dict)
    {
        dict.Add(string.Format("PLAYERFEATURE_LEVEL_{0}", level), enabled);
    }

    private static Dictionary<string, object> CompileTimeConstantsFor(FlashPostProcessSettings settings)
    {
        Dictionary<string, object> dictionary2 = new Dictionary<string, object>();
        dictionary2.Add("TargetFlashPlayerVersion", settings.GetTargetPlayerForSubtarget());
        dictionary2.Add("TargetSwfVersion", settings.GetSwfVersionForPlayerVersion().ToString());
        Dictionary<string, object> dict = dictionary2;
        AddConfigDefineForFlashPlayerFeatureLevel(settings.FlashBuildSubtarget >= UnityEditor.FlashBuildSubtarget.Flash11dot2, "11dot2", dict);
        AddConfigDefineForFlashPlayerFeatureLevel(settings.FlashBuildSubtarget >= UnityEditor.FlashBuildSubtarget.Flash11dot3, "11dot3", dict);
        AddConfigDefineForFlashPlayerFeatureLevel(settings.FlashBuildSubtarget >= UnityEditor.FlashBuildSubtarget.Flash11dot4, "11dot4", dict);
        return dict;
    }

    public static FlashPostProcessSettings CreateFrom(PostProcessFlashPlayerOptions options)
    {
        return CreateWithBuildArguments(options.Options, options.Width, options.Height);
    }

    public static FlashPostProcessSettings CreateWithBuildArguments(BuildOptions options, int width, int height)
    {
        return new FlashPostProcessSettings { Width = Math.Min(Math.Max(width, 1), 0x1000), Height = Math.Min(Math.Max(height, 1), 0x1000), StripPhysics = PlayerSettings.stripPhysics, IsDevelopment = (options & BuildOptions.Development) != BuildOptions.None, FlashBuildSubtarget = EditorUserBuildSettings.flashBuildSubtarget };
    }

    private static string EncodeMxmlcConstant(object value)
    {
        if (value is string)
        {
            return string.Format("\"'{0}'\"", value);
        }
        return value.ToString().ToLower();
    }

    internal int GetSwfVersionForPlayerVersion()
    {
        switch (this.FlashBuildSubtarget)
        {
            case UnityEditor.FlashBuildSubtarget.Flash11dot2:
                return 15;

            case UnityEditor.FlashBuildSubtarget.Flash11dot3:
                return 0x10;

            case UnityEditor.FlashBuildSubtarget.Flash11dot4:
                return 0x11;
        }
        return 15;
    }

    internal string GetTargetPlayerForSubtarget()
    {
        switch (this.FlashBuildSubtarget)
        {
            case UnityEditor.FlashBuildSubtarget.Flash11dot2:
                return "11.2.0";

            case UnityEditor.FlashBuildSubtarget.Flash11dot3:
                return "11.3.0";

            case UnityEditor.FlashBuildSubtarget.Flash11dot4:
                return "11.4.0";
        }
        return "11.2.0";
    }

    internal string GetUnityNativeSwcForSubTarget(bool stripPhysics)
    {
        string str;
        switch (this.FlashBuildSubtarget)
        {
            case UnityEditor.FlashBuildSubtarget.Flash11dot2:
            case UnityEditor.FlashBuildSubtarget.Flash11dot3:
            case UnityEditor.FlashBuildSubtarget.Flash11dot4:
                str = "UnityNative11dot2";
                break;

            default:
                str = "UnityNative11dot2";
                break;
        }
        if (this.StripPhysics)
        {
            str = str + "_nophysx";
        }
        return (str + ".swc");
    }

    internal string MxmlcCompileTimeConstants()
    {
        if (<>f__am$cache5 == null)
        {
            <>f__am$cache5 = (agg, value) => agg + string.Format("-define+={0}::{1},{2} ", "UNITY_FLASH", value.Key, EncodeMxmlcConstant(value.Value));
        }
        return Enumerable.Aggregate<KeyValuePair<string, object>, string>(CompileTimeConstantsFor(this), string.Empty, <>f__am$cache5);
    }
}

